# Create your views here.
from django.http import Http404, HttpRequest, HttpResponse
from django.shortcuts import render_to_response
from django.contrib.auth.models import User
from b52.home.models import *
from django.http import HttpResponseRedirect


def activate_users(request):
    if ( request.user.is_authenticated() and request.user.is_staff):
        userProfiless = UserProfile.objects.filter(is_new=True)
        #userP = UserProfile(is_new=True, is_payed = False)
        #userP.user = User(username="login", is_active=False)
        return render_to_response('basement/to_activate.html',
                    {
                        'data': {
                            'data': userProfiless,
                            'top': 'top top top',
                            'title': 'This is Users for activation',
                        }
                    }
        )
    else:
        return HttpResponseRedirect('/login/?next=%s' % request.path)

def activate_users_by_id(request, i_user):
    if ( request.user.is_authenticated() and request.user.is_staff):
        # Do something for authenticated users.
        user = User.objects.get(id=i_user)
        user.is_active = True
        user.get_profile().is_new = False
        user.get_profile().save()
        user.save()
        
        return HttpResponseRedirect('/basement/show/to_activate/')
    else:
        return HttpResponseRedirect('/login/?next=%s' % request.path)
        # Do something for anonymous users.
    